/**
 * Created by XianTao on 2016/11/14
 * <p/>
 * Copyright (c) 2015-2015
 * Apache License
 * Version 2.0, January 2004
 * http://www.apache.org/licenses/
 */
package org.lego.wechat.base.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.lego.jpa.base.entity.UUIDWithTimeEntity;
import org.springframework.util.ObjectUtils;

import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
public class WxJsAccessToken extends UUIDWithTimeEntity {
    private String corpId;
    private Integer agentId;
    private String jsAccessToken;
    private Integer expiredTime;
    private String refreshToken;
    private String openId;  // 授权微信号能获取其信息的用户id
    private String scope;   // 用户授权的作用域，使用逗号（,）分隔
    private String unionId; // 只有在用户将公众号绑定到微信开放平台帐号后，才会出现该字段

    public String getJsAccessToken() {
        if (ObjectUtils.isEmpty(this.jsAccessToken)) {
            return "";
        }
        return this.jsAccessToken.substring(3, this.jsAccessToken.length() - 2);
    }

    public void setJsAccessToken(String accessToken) {
        this.jsAccessToken = "Ltt" + accessToken + "ai";
    }
}
